package c.e.a.b.e.c;

import c.e.a.b.e.c.u4.b;
import c.e.a.b.e.c.u4.d;
import c.e.a.b.e.c.u4.f;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;

/* compiled from: com.google.android.gms:play-services-measurement-base@@18.0.0 */
public final class i6<T> implements s6<T> {
    public final e6 a;
    public final f7<?, ?> b;
    public final boolean c;
    public final j4<?> d;

    public i6(f7<?, ?> f7Var, j4<?> j4Var, e6 e6Var) {
        this.b = f7Var;
        this.c = j4Var.e(e6Var);
        this.d = j4Var;
        this.a = e6Var;
    }

    public final int a(T t) {
        int hashCode = this.b.e(t).hashCode();
        return this.c ? (hashCode * 53) + this.d.b(t).hashCode() : hashCode;
    }

    public final boolean b(T t) {
        return this.d.b(t).m();
    }

    public final boolean c(T t, T t2) {
        if (this.b.e(t).equals(this.b.e(t2))) {
            return this.c ? this.d.b(t).equals(this.d.b(t2)) : true;
        } else {
            return false;
        }
    }

    public final void d(T t) {
        this.b.h(t);
        this.d.g(t);
    }

    public final int e(T t) {
        f7 f7Var = this.b;
        int i = 0;
        int i2 = f7Var.i(f7Var.e(t)) + 0;
        if (!this.c) {
            return i2;
        }
        n4 b = this.d.b(t);
        int i3 = 0;
        while (i < b.a.e()) {
            i3 += n4.k(b.a.d(i));
            i++;
        }
        for (Entry k : b.a.g()) {
            i3 += n4.k(k);
        }
        return i2 + i3;
    }

    public final void f(T t, x7 x7Var) throws IOException {
        Iterator l = this.d.b(t).l();
        while (l.hasNext()) {
            Entry entry = (Entry) l.next();
            p4 p4Var = (p4) entry.getKey();
            if (p4Var.s() != y7.MESSAGE || p4Var.f() || p4Var.g()) {
                throw new IllegalStateException("Found invalid MessageSet item.");
            } else if (entry instanceof h5) {
                ((g4) x7Var).c(p4Var.q(), ((f5) ((h5) entry).a.getValue()).c());
            } else {
                ((g4) x7Var).c(p4Var.q(), entry.getValue());
            }
        }
        f7 f7Var = this.b;
        f7Var.f(f7Var.e(t), x7Var);
    }

    public final void g(T t, byte[] bArr, int i, int i2, s3 s3Var) throws IOException {
        u4 u4Var = (u4) t;
        e7 e7Var = u4Var.zzb;
        if (e7Var == e7.f) {
            e7Var = e7.c();
            u4Var.zzb = e7Var;
        }
        ((d) t).u();
        f fVar = null;
        while (i < i2) {
            int p = c.e.a.b.b.j.d.p(bArr, i, s3Var);
            int i3 = s3Var.a;
            p6 p6Var;
            if (i3 == 11) {
                i = 0;
                Object obj = null;
                while (p < i2) {
                    p = c.e.a.b.b.j.d.p(bArr, p, s3Var);
                    int i4 = s3Var.a;
                    int i5 = i4 >>> 3;
                    int i6 = i4 & 7;
                    if (i5 != 2) {
                        if (i5 == 3) {
                            if (fVar != null) {
                                p6Var = p6.c;
                                throw new NoSuchMethodError();
                            } else if (i6 == 2) {
                                p = c.e.a.b.b.j.d.P(bArr, p, s3Var);
                                obj = (t3) s3Var.c;
                            }
                        }
                    } else if (i6 == 0) {
                        p = c.e.a.b.b.j.d.p(bArr, p, s3Var);
                        i = s3Var.a;
                        fVar = (f) this.d.c(s3Var.d, this.a, i);
                    }
                    if (i4 == 12) {
                        break;
                    }
                    p = c.e.a.b.b.j.d.h(i4, bArr, p, i2, s3Var);
                }
                if (obj != null) {
                    e7Var.a((i << 3) | 2, obj);
                }
                i = p;
            } else if ((i3 & 7) == 2) {
                fVar = (f) this.d.c(s3Var.d, this.a, i3 >>> 3);
                if (fVar == null) {
                    i = c.e.a.b.b.j.d.j(i3, bArr, p, i2, e7Var, s3Var);
                } else {
                    p6Var = p6.c;
                    throw new NoSuchMethodError();
                }
            } else {
                i = c.e.a.b.b.j.d.h(i3, bArr, p, i2, s3Var);
            }
        }
        if (i != i2) {
            throw e5.d();
        }
    }

    public final void h(T t, T t2) {
        f7 f7Var = this.b;
        Class cls = u6.a;
        f7Var.d(t, f7Var.g(f7Var.e(t), f7Var.e(t2)));
        if (this.c) {
            u6.i(this.d, t, t2);
        }
    }

    public final T q() {
        return ((b) this.a.d()).k();
    }
}
